//
//  HPWithdrawViewController.m
//  HPZZTong
//
//  Created by handpay on 14-10-22.
//  Copyright (c) 2014年 handpay. All rights reserved.
//

#import "HPWithdrawViewController.h"

@interface HPWithdrawViewController (){
    
    IBOutlet UIView *desView;
    IBOutlet UIButton *recordButton;
    IBOutlet UIButton *withdrawButton;
    IBOutlet UILabel *tipsLabel;
    IBOutlet UILabel *desLabel;
}
- (IBAction)withdrawClick:(id)sender;
- (IBAction)recordClick:(id)sender;

@end

@implementation HPWithdrawViewController

- (void)viewDidLoad {
    self.title = @"收款提现";
    [super viewDidLoad];
    
    [withdrawButton setBackgroundImage:[[UIImage imageNamed:@"bluebutton.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:0] forState:UIControlStateNormal];
    
    [withdrawButton setBackgroundImage:[[UIImage imageNamed:@"bluebuttonhover.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:0] forState:UIControlStateHighlighted];
    
    [withdrawButton setBackgroundImage:[[UIImage imageNamed:@"unclickbutton.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:0] forState:UIControlStateDisabled];
    
    [recordButton setBackgroundImage:[[UIImage imageNamed:@"yellowbutton.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:0] forState:UIControlStateNormal];
    
    [recordButton setBackgroundImage:[[UIImage imageNamed:@"yellowbuttonhover.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:0] forState:UIControlStateHighlighted];
    
    [recordButton setBackgroundImage:[[UIImage imageNamed:@"unclickbutton.png"] stretchableImageWithLeftCapWidth:9 topCapHeight:0] forState:UIControlStateDisabled];
    
    if(ZZT_CLIENG.accountInfo){
        NSString* wdPermiss = ZZT_CLIENG.accountInfo.wdPermission;
        NSString* subPre = nil;
        NSString* subLast = nil;
        //wdPermiss等于11，withdrawButton为可见可用， 10可见不可用，01不可见可用，00不可见不可用
        if (![NSString isNilOrEmpty:wdPermiss]) {
            subPre = [wdPermiss substringToIndex:1];
            subLast = [wdPermiss substringWithRange:NSMakeRange(1, 1)];
        }
        
        if (![NSString isNilOrEmpty:subPre] && [subPre isEqualToString:@"1"]) {
            withdrawButton.hidden = NO;
            
            if (![NSString isNilOrEmpty:subLast] && ![subLast isEqualToString:@"1"]) {
                withdrawButton.enabled = NO;
            }
        }
    }
//    //根据提示文字不同的界面显示
//    [desLabel sizeToFit];
//    [tipsLabel sizeToFit];
//    
//    CGRect desFrame = desLabel.frame;
//    
//    CGRect frame = desView.frame;
//    frame.size.height = desFrame.size.height + 30;
//    desView.frame = frame;
//    
//    CGRect tipsFrame = tipsLabel.frame;
//    tipsFrame.origin.y = frame.origin.y + frame.size.height + 20;
//    tipsLabel.frame = tipsFrame;
//    
//    CGRect withdrawFrame = withdrawButton.frame;
//    withdrawFrame.origin.y = tipsFrame.origin.y + tipsFrame.size.height + 25;
//    withdrawButton.frame = withdrawFrame;
//    
//    CGRect recordFrame = recordButton.frame;
//    
//    int bottom = withdrawFrame.origin.y + withdrawFrame.size.height + 15;
//    recordFrame.origin.y = bottom;
//    recordButton.frame = recordFrame;
//    
//    bottom += recordFrame.size.height + 20;
//    
//    UIScrollView* scrollV = (UIScrollView*)self.view;
//    if (bottom > scrollV.frame.size.height) {
//        scrollV.contentSize = CGSizeMake(scrollV.frame.size.width, bottom);
//    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)dealloc {
    [desLabel release];
    [tipsLabel release];
    [withdrawButton release];
    [recordButton release];
    [desView release];
    [super dealloc];
}
- (IBAction)withdrawClick:(id)sender {
    withdrawButton.userInteractionEnabled = NO;
    ZZTongClientEngine* zzt = ZZT_CLIENG;
    NSDictionary* params = @{KEY_CHANNEL: [zzt getChannel],
                             @"account":DES_ENC(zzt.accountInfo.account)};
    LOG(@"params:%@", params);
    [zzt.netEngine sendRequest:NET_ACTION_WITHDRAW withParams:params withDelegate:self];
    [zzt.uiEngine showNetWaiting];
}
- (IBAction)recordClick:(id)sender {
    [HPUIENG showScreen:SCR_RWD_RECORDS];
}


- (void)responseCallBackSuccess:(NSString *)action withData:(NSDictionary *)respData{
    [HPUIENG removeWaiting];
    if ([action isEqualToString:NET_ACTION_WITHDRAW]) {
        withdrawButton.userInteractionEnabled = YES;
        NSString* responseCode = [respData objectForKey:@"responseCode"];
        NSString* message = [respData objectForKey:@"message"];
        if (![NSString isNilOrEmpty:message]) {
            [HPUIENG showAlert:message];
            return;
        }
        
        if (![NSString isNilOrEmpty:responseCode] && [responseCode isEqualToString:@"0"] ) {
            [HPUIENG showAlert:@"申请成功"];
        }else{
            [HPUIENG showAlert:@"申请失败"];
        }
    }
}

- (void)responseCallBackFailed:(NSString *)action withErrCode:(NSString *)errCode withErrMsg:(NSString *)msg{
    if ([action isEqualToString:NET_ACTION_WITHDRAW]) {
        withdrawButton.userInteractionEnabled = YES;
    }
}
@end
